{% raw %}
<!--edit entry modal-->
<div class="modal fade" id="edit-entry" ng-controller="EntryCtrl">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">


      <!-- header -->
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <ul class="nav nav-pills">
          <li ng-class="{active: panel=='request'}">
            <a href="javascript:void(0)" ng-click="panel='request'">Request</a>
          </li>
          <li ng-class="{active: panel=='response'}">
            <a href="javascript:void(0)" ng-click="panel='response'">Response</a>
          </li>
          <li ng-class="{active: panel=='test'}">
            <a href="javascript:void(0)" ng-click="panel='test'">测试</a>
          </li>
          <li ng-class="{active: panel=='preview'}">
            <a href="javascript:void(0)" ng-click="panel='preview'">预览</a>
          </li>
          <li ng-class="{active: panel=='preview-headers'}" ng-show="preview">
            <a href="javascript:void(0)" ng-click="panel='preview-headers'">结果 Headers</a>
          </li>
        </ul>
      </div>


      <!-- request -->
      <div class="modal-body" ng-show="panel=='request'">
        <!-- url and method -->
        <dl class="dl-horizontal">
          <dt>Request URL</dt>
          <dd>
            <div class="contentedit-wrapper" ng-bind-html="variables_wrapper(entry.request.url, 'request url')"></div>
            <div contenteditable style="display: none" ng-model="entry.request.url"></div>
          </dd>
          <dt>Request Method</dt>
          <dd contenteditable data-ph="request method" ng-model="entry.request.method"></dd>
        </dl>

        <!-- query string -->
        <details open onclick="return false">
          <summary>
            Query String Parameters
            <a class="btn btn-info btn-xxs"
              ng-click="entry.request.queryString.unshift({name: ':key', value: ':value'})">ADD</a>
          </summary>
          <div editablelist="entry.request.queryString"></div>
        </details>

        <!-- headers -->
        <details open onclick="return false">
          <summary>
            Request Headers
            <a class="btn btn-info btn-xxs"
              ng-click="entry.request.headers.unshift({name:'', value:'', checked: true})">ADD</a>
          </summary>
          <div editablelist="entry.request.headers"></div>
        </details>
        <!-- headers end -->


        <!-- cookies -->
        <details open onclick="return false">
          <summary>
            Cookies
            <a class="btn btn-info btn-xxs"
              ng-click="entry.request.cookies.unshift({name:'', value:'', checked:true})">ADD</a>
          </summary>
          <div editablelist="entry.request.cookies"></div>
        </details>
        <!-- cookie end -->

        <!--post data-->
        <details open onclick="return false" ng-if="entry.request.postData.text">
          <summary>
            Request Payload
            <a class="btn btn-info btn-xxs" ng-if="entry.request.postData.params"
              ng-click="entry.request.postData.params.unshift({name:'', value:''})">ADD</a>
          </summary>
          <pre class="contentedit-wrapper" ng-bind-html="variables_wrapper(entry.request.postData.text)" ng-if="!entry.request.postData.params"></pre>
          <textarea contenteditable style="width: 100%" rows="5" onfocus="$(this).height($(this)[0].scrollHeight);" ng-model="entry.request.postData.text" ng-if="!entry.request.postData.params"></textarea>
          <div ng-if="entry.request.postData.params">
            <div editablelist="entry.request.postData.params"></div>
          </div>
        </details>
      </div>
      <!-- /.reqeust -->


      <!-- response -->
      <div class="modal-body" ng-show="panel=='response'">
        <dl class="dl-horizontal">
          <dt>Status Code</dt>
          <dd><span class="label {{ status_label(entry.response.status) }}">{{ entry.response.status }}</span></dd>
        </dl>
        <details open onclick="return false">
          <summary>Response Headers</summary>
          <dl class="dl-horizontal">
            <dt ng-repeat-start="header in entry.response.headers">{{ header.name }}</dt>
            <dd ng-repeat-end>{{ header.value }}</dd>
          </dl>
        </details>
        <details open onclick="return false">
          <summary>Cookies</summary>
          <dl class="dl-horizontal">
            <dt ng-repeat-start="cookie in entry.response.cookies">{{ cookie.name }}</dt>
            <dd ng-repeat-end>{{ cookie.value }}</dd>
          </dl>
        </details>
      </div>
      <!-- /.response -->


      <!-- test -->
      <div class="modal-body panel-test" ng-show="panel=='test'">
        <div class="alert alert-danger" role="alert">
          <strong>Oh snap!</strong> Change a few things up and try submitting again.
        </div>
        <details open onclick="return false">
          <summary>
            Variables
            <a class="btn btn-info btn-xxs" ng-click="env.unshift({name:'', value:''})">ADD</a>
          </summary>
          <div editablelist="env"></div>
        </details>
        <details open onclick="return false">
          <summary>
            Cookies
            <a class="btn btn-info btn-xxs" ng-click="session = []">CLEAR</a>
          </summary>
          <dl class="dl-horizontal">
            <dt ng-repeat-start="cookie in session">{{ cookie.name }}</dt>
            <dd ng-repeat-end>{{ cookie.value }}</dd>
          </dl>
        </details>
      </div>
      <!-- /.test -->


      <!-- preview-headers -->
      <div class="modal-body" ng-if="preview" ng-show="panel=='preview-headers'">
        <dl class="dl-horizontal">
          <dt>Request URL</dt>
          <dd>{{ preview.request.url }}</dd>
          <dt>Request Method</dt>
          <dd>{{ preview.request.method }}</dd>
          <dt>Status Code</dt>
          <dd><span class="label {{ status_label(preview.response.status) }}">{{ preview.response.status }}</span></dd>
        </dl>

        <!-- request header -->
        <details open>
          <summary>Request Headers</summary>
          <dl class="dl-horizontal">
            <dt ng-repeat-start="header in preview.request.headers">{{ header.name }}</dt>
            <dd ng-repeat-end>{{ header.value }}</dd>
          </dl>
        </details>
        <!-- request payload -->
        <details open ng-if="preview.request.postData.text">
          <summary>Request Payload</summary>
          <pre ng-bind-html="variables_wrapper(preview.request.postData.text)" ng-if="!preview.request.postData.params"></pre>
          <dl class="dl-horizontal" ng-if="preview.request.postData.params">
            <dt ng-repeat-start="each in preview.request.postData.params">{{ each.name }}</dt>
            <dd ng-repeat-end>{{ each.value }}</dd>
          </dl>
        </details>
        <!-- request query string -->
        <details open ng-if="!preview.reqeust.postData.text && preview.request.queryString.length > 0">
          <summary>Query String Parameters</summary>
          <dl class="dl-horizontal">
            <dt ng-repeat-start="each in preview.request.queryString">{{ each.name }}</dt>
            <dd ng-repeat-end>{{ each.value }}</dd>
          </dl>
        </details>

        <!-- response headers -->
        <details open>
          <summary>Response Headers</summary>
          <dl class="dl-horizontal">
            <dt ng-repeat-start="each in preview.response.headers">{{ each.name }}</dt>
            <dd ng-repeat-end>{{ each.value }}</dd>
          </dl>
        </div>
        <!-- /.preview-headers -->


        <!-- preview -->
        <div class="modal-body panel-preview" ng-show="panel=='preview'">
          <div>
            <span>Status Code:</span>
            <span class="label {{ status_label(preview.response.status) }}">{{ preview.response.status }}</span>
            <span ng-switch="preview.success">
              <span class="glyphicon glyphicon-ok text-success" ng-switch-when="true"></span>
              <span class="glyphicon glyphicon-remove text-danger" ng-switch-when="false"></span>
            </span>
          </div>

          <details class="preview-assert" open onclick="return false">
            <summary>
              请求成功条件断言
              <small>支持正则，任意条件满足即为请求成功（没有失败条件命中时）</small>
              <a class="btn btn-info btn-xxs"
                ng-click="entry.success_asserts.unshift({re:'', from:'content'})">ADD</a>
            </summary>
            <dl class="dl-horizontal">
              <dt ng-repeat-start="rule in entry.success_asserts">
                <select ng-model="rule.from" ng-options="v for v in ['content', 'status', 'header-location']"></select>
                <div class="input-wrapper">
                  <input placeholder="rule" ng-model="rule.re">
                </div>
                <span class="eq">=</span>
              </dt>
              <dd ng-repeat-end>
              <span class="btn btn-default btn-xxs remove pull-right"
                ng-click="delete(rule.$$hashKey, entry.success_asserts)"></span>
              <span>{{ preview_match(rule.re, rule.from) }}</span>
              <span ng-switch="preview_match(rule.re, rule.from)">
                <span class="glyphicon glyphicon-remove text-danger" ng-switch-when="null"></span>
                <span class="glyphicon glyphicon-ok text-success" ng-switch-default></span>
              </span>
              </dd>
            </dl>
          </details>

          <details class="preview-assert" open onclick="return false">
            <summary>
              请求失败条件断言
              <small>支持正则，任意条件满足即为请求失败</small>
              <a class="btn btn-info btn-xxs"
                ng-click="entry.failed_asserts.unshift({re:'', from:'content'})">ADD</a>
            </summary>
            <dl class="dl-horizontal">
              <dt ng-repeat-start="rule in entry.failed_asserts">
                <select ng-model="rule.from" ng-options="v for v in ['content', 'status', 'header-location']"></select>
                <div class="input-wrapper">
                  <input placeholder="rule" ng-model="rule.re">
                </div>
                <span class="eq">=</span>
              </dt>
              <dd ng-repeat-end>
              <span class="btn btn-default btn-xxs remove pull-right"
                ng-click="delete(rule.$$hashKey, entry.failed_asserts)"></span>
              <span>{{ preview_match(rule.re, rule.from) }}</span>
              <span ng-switch="preview_match(rule.re, rule.from)">
                <span class="glyphicon glyphicon-remove text-danger" ng-switch-default></span>
                <span class="glyphicon glyphicon-minus text-info" ng-switch-when="null"></span>
              </span>
              </dd>
            </dl>
          </details>

          <details class="extract-variables" open onclick="return false">
            <summary>
              变量提取
              <small>支持正则，支持括号表达式</small>
              <a class="btn btn-info btn-xxs"
                ng-click="entry.extract_variables.unshift({name: '', re:'', from:'content'})">ADD</a>
            </summary>
            <dl class="dl-horizontal">
              <dt ng-repeat-start="rule in entry.extract_variables">
                <div class="input-wrapper">
                  <input placeholder="name" ng-model="rule.name">
                </div>
                <span class="eq">=</span>
                <div class="input-wrapper">
                  <input placeholder="rule" ng-model="rule.re">
                </div>
                <span class="eq">=</span>
              </dt>
              <dd ng-repeat-end>
              <span class="btn btn-default btn-xxs remove pull-right"
                ng-click="delete(rule.$$hashKey, entry.extract_variables)"></span>
              <span>{{ preview_match(rule.re, rule.from) }}</span>
              </dd>
            </dl>
          </details>

          <iframe sandbox></iframe>
        </div>
        <!-- /.preview -->


        <!-- footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-success do-test" data-loading-test="Loading..."
            ng-show="panel=='test' || panel=='preview' || panel=='preview-headers'"
            ng-click="do_test()">测试</button>
          <button type="button" class="btn btn-primary" data-loading-text="Saving..." data-dismiss="modal">Save</button>
        </div>
        <!-- /.footer -->
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
</div>
{% endraw %}
